$(function() {
    var id = location.search.split("?")[1].split("=")[1];
    console.log(111);
    $.ajax({
        url: "/cart/getGoodsById",
        type: "get",
        data: { id },
        headers: {
            token: localStorage.token
        }
    }).done(function(res) {
        console.log(res);
        let { data } = res;
        $(".detail-title").text(data.name)
        $(".price").text(data.price)
        $(".oldprice1").text(data.oldPrice)
        $(".J_ImgBooth").attr("src", data.sImg)
        $(".ks-zoom-img").attr("src", data.bImg)
    })
})

$(function() {
    var user = JSON.parse(sessionStorage.getItem("userInfo"))
    if (user != null || user != undefined) {
        $(".button-add").on("click", function() {
            // 1.产品id
            var id = location.search.split("?")[1].split("=")[1];
            // 2.产品名称
            var name = $(".detail-title").text();
            // 3.产品的价格
            var price = $(".price").text();
            // 4.产品的数量
            var number = $(".xSalesAction-NumberTxt ").val();
            // 5.图片
            var img = $(".J_ImgBooth").attr("src");
            // 6.购买人
            var uId = JSON.parse(sessionStorage.getItem("userInfo") || '{}').uId;
            // 7.规格
            var color = $(".colTrue>div").attr("title");
            var size = $(".sizeTrue div").text();
            console.log(id, name, price, number, img, uId, color, size);

            $.ajax({
                url: "/cart/add",
                type: "post",
                data: {
                    id,
                    name,
                    price,
                    number,
                    img,
                    uId,
                    size,
                    color
                },
                headers: {
                    token: localStorage.token
                }
            }).then(function(res) {
                console.log(res);
            })
        })
    }
})